package com.example.zhu.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhu.Utils.UserHolder;
import com.example.zhu.VO.RoomVo.RoomVO;
import com.example.zhu.dto.DeptPO;
import com.example.zhu.Mapper.DeptMapper;
import com.example.zhu.Mapper.RoomMapper;
import com.example.zhu.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class RoomServiceImpl  implements IRoomService {
    @Autowired
    DeptMapper deptMapper;

    @Autowired
    RoomMapper roomMapper;


    @Override
    public List<RoomVO> getAllList(RoomVO roomVO) {
        String floor = roomVO.getFloor();
        String name = roomVO.getName();
        if (floor != null && !floor.equals("")) {
            floor="%"+floor.trim()+"%";
            List<RoomVO> roomVOS= roomMapper.selectFloorList(floor);
            return roomVOS;
        }else if (name != null && !name.equals("")) {
            name="%"+name.trim()+"%";
            List<RoomVO> roomVOS= roomMapper.selectNameList(name);
            return roomVOS;
        }
        return roomMapper.getAllList(roomVO);
    }


    @Override
    public List<String> getFloor() {
        List<RoomVO> roomPOS = roomMapper.selectList();
        Iterator<RoomVO> iterator = roomPOS.iterator();
        List<String> floors = new ArrayList<>();
        while (iterator.hasNext()) {
            floors.add(iterator.next().getFloor());
        }
        return floors;
    }




}
